using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace SomeGame
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Person : Actor
    {
        private int health;
        public int Health
        {
            get{return this.health;}
            set{this.health = value;}
        }
        private int mana;
        public int Mana
        {
            get { return this.mana; }
            set { this.mana = value; }
        }
        private int strength;
        public int Strength
        {
            get { return this.strength; }
            set { this.strength = value; }
        }
        private int honor;
        public int Honor
        {
            get { return this.honor; }
            set { this.honor = value; }
        }
        private int magic;
        public int Magic
        {
            get { return this.magic; }
            set { this.magic = value; }
        }
        private int charisma;
        public int Charisma
        {
            get { return this.charisma; }
            set { this.charisma = value; }
        }
        private int lives;
        public int Lives
        {
            get { return this.lives; }
            set { this.lives = value; }
        }
        private int manaPots;
        public int ManaPots
        {
            get { return this.manaPots; }
            set { this.manaPots = value; }
        }
        private int healthPots;
        public int HealthPots
        {
            get { return this.healthPots; }
            set { this.healthPots = value; }
        }
        private int monies;
        public int Monies
        {
            get { return this.monies; }
            set { this.monies = value; }
        }
        private int status;
        public int Status
        {
            get { return this.status; }
            set { this.status = value; }
        }

        private int maxMana;
        public int MaxMana
        {
            get { return this.maxMana; }
            set { this.maxMana = value; }
        }

        private int maxHealth;
        public int MaxHealth
        {
            get { return this.maxHealth; }
            set { this.maxHealth = value; }
        }

        private bool isControlledByMouse;
        public bool IsControlledByMouse
        {
            get{ return this.isControlledByMouse; }
            set { this.isControlledByMouse = value; }
        }

        private bool cWasPressed;

        private KeyboardState keyboard;
        private MouseState mouseState;

        public Person(Game1 game, int health, int mana, int strength, int honor, int magic, int lives, int monies, bool control)
            : base(game)
        {
            game.Components.Add(this);
            this.health = health;
            this.mana = mana;
            this.strength = strength;
            this.honor = honor;
            this.magic = magic;
            this.lives = lives;
            this.monies = monies;
            this.charisma = honor + (health / 2);
            this.manaPots = 0;
            this.healthPots = 0;
            this.status = 0;
            this.maxHealth = health;
            this.maxMana = mana;
            this.isControlledByMouse = control;

            // TODO: Construct any child components here
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            if (isControlledByMouse)
            {
                MouseControl();
            }
            else
            {
                KeyboardInput();
            }

            base.Update(gameTime);
        }

        private void MouseControl()
        {
            mouseState = Mouse.GetState();

            this.position = new Vector2(mouseState.X, mouseState.Y);
        }

        private void KeyboardInput()
        {
            keyboard = Keyboard.GetState();

            if (keyboard.IsKeyDown(Keys.Up))
            {
                this.position.Y -= 5;
            }
            if (keyboard.IsKeyDown(Keys.Down))
            {
                this.position.Y += 5;
            }
            if(keyboard.IsKeyDown(Keys.Left))
            {
                this.position.X -= 5;
            }
            if (keyboard.IsKeyDown(Keys.Right))
            {
                this.position.X += 5;
            }
        }
    }
}
